# DjangoDE, an integrated development environment for Django
# Copyright (C) 2010-2011 Andrew Wilkinson
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

from djangode import global_objects
from djangode.data.codemodel import AttributeDoesNotExist, CodeModel, Module, builtins

def module_name(module_name):
    return []

def module_content(module_name, variable_name):
    return []

def variable(editor, line_number, variable_name):
    return []

def attribute(editor, line_number, variable_name):
    module = CodeModel.get_model().get_module_from_editor(editor)

    try:
        var = module.get_variable(variable_name).value
    except AttributeDoesNotExist:
        return None

    if var.is_instance_of(builtins.get_variable("module").value.type):
        return var.get_attributes(nested=False)
    else:
        return var.get_attributes()
